from selenium.common.exceptions import NoSuchElementException

class LoginPage:
    def __init__(self, driver):
        self.driver = driver
    def chech_login(self):
        print("检查是否已经有登陆账号")
        try:
            el6 = self.driver.find_element_by_id("com.xqxc.customer:id/settingIbtn")

        except NoSuchElementException:
            print("没有账号登陆")
            back = self.driver.find_element_by_id("com.xqxc.customer:id/mBackIV")
            back.click()
        else:
            el6.click()
            el7 = self.driver.find_element_by_xpath(
                "/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.ScrollView/android.widget.LinearLayout/android.widget.Button")
            el7.click()
            el8 = self.driver.find_element_by_id("com.xqxc.customer:id/account_pwd_tip")
            el8.click()
            back = self.driver.find_element_by_id("com.xqxc.customer:id/mBackIV")
            back.click()
            return self
    def login_pwd(self, tel, password):

        el3 = self.driver.find_element_by_id("com.xqxc.customer:id/phoneNoEt")
        el3.send_keys(tel)
        el4 = self.driver.find_element_by_id("com.xqxc.customer:id/pwdEt")
        el4.send_keys(password)
        el5 = self.driver.find_element_by_id("com.xqxc.customer:id/login_btn")
        el5.click()
        print("账号：%d登陆成功" %tel)
        return self

    def login_message(self, tel, message):

        el3 = self.driver.find_element_by_id("com.xqxc.customer:id/phoneNoEt")
        el3.send_keys(tel)
        el4 = self.driver.find_element_by_id("com.xqxc.customer:id/pwdEt")
        el4.send_keys(message)
        el5 = self.driver.find_element_by_id("com.xqxc.customer:id/login_btn")
        el5.click()
        print("账号：%d登陆成功" %tel)
        return self